<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--
@html_name: 12promise封装ajax请求
@description: The past cannot be redeemed, the future can be changed.
@author: Jason Black
@create: 2023/6/26 08:38:47
-->
<script>
    const p = new Promise((resolve, reject) => {
        const request = new XMLHttpRequest()
        request.open("GET", "https://api.apiopen.top/get")
        request.send()
        request.onreadystatechange = () => {
            if (request.readyState === 4) {
                if (request.status >= 200 && request.status < 300) {
                    resolve(request.response)
                } else {
                    reject(request.status)
                }
            }
        }
    })
    p.then(value => {
        console.log(value)
    },reason => {
        console.error(reason)
    })
</script>
</body>
</html>